﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainFrame
{
    public partial class PageAlarm : Form
    {
        public PageAlarm(AlarmInfo info)
        {
            InitializeComponent();
            curInfo = info;
        }
        private AlarmInfo curInfo;
        private void PageAlarm_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new System.Drawing.Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
                (Screen.PrimaryScreen.WorkingArea.Height - this.Height - (this.Height / 2)));
            try
            {
                if (curInfo != null)
                {
                    this.Invoke(new Action(() => {
                        //richTextBox1.Text = "时间                      " + "信息" + Environment.NewLine +
                        //     curInfo.startTime.ToString("yyyy-MM-dd HH:mm:ss    ")+ curInfo.AlarmMsg + "涉及产品ID:" + curInfo.ProIds;
                        richTextBox1.Text= curInfo.startTime.ToString("yyyy-MM-dd HH:mm:ss    ") + curInfo.AlarmMsg + "涉及产品ID:" + curInfo.ProIds;
                    })); 
                }
                this.Refresh();
               
            }
            catch
            {

            }
           
        }
        public void addAlarmInfo(AlarmInfo info)
        {
            try
            {
                if (curInfo != null)
                {
                    this.Invoke(new Action(() => {
                        if (richTextBox1.Lines.Length > 100)
                            richTextBox1.Text = "";
                        //richTextBox1.Text = "时间                      " + "信息" + Environment.NewLine +
                        //     curInfo.startTime.ToString("yyyy-MM-dd HH:mm:ss    ")+ curInfo.AlarmMsg + "涉及产品ID:" + curInfo.ProIds;
                        richTextBox1.AppendText (Environment.NewLine+ info.startTime.ToString("yyyy-MM-dd HH:mm:ss    ") + info.AlarmMsg + "涉及产品ID:" + info.ProIds);
                    }));
                }
                this.Refresh();
              //  this.Show();
            }
            catch
            {

            }
        }
        private void PageAlarm_FormClosed(object sender, FormClosedEventArgs e)
        {
            richTextBox1.Text = "";
            GlobalVar.btn_Estop.Invoke("急停取消");
        }

        private void PageAlarm_FormClosing(object sender, FormClosingEventArgs e)
        {
            GlobalMotion.LightState(e_LightState.None);
        }
    }
}
